<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html>
 <head>
	<style type="text/css"> 
		fieldset,table,tr,td {margin:0; padding:0;}
		td {padding:0 5px 0 10px;border:1px;}
		form label {font-weight:bold;}
		table{border-collapse: collapse;}
	</style>

  <script type="text/javascript">
	$(document).ready(function() {

		$.ajaxSetup({ cache : false, async : false });
		//异步提交表单
		var options = {
			dataType : 'json',
			beforeSubmit : checkSubmit,
			success : process
		};
		
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#roleForm").submit();
        });
	}); 
	
	function checkSubmit() {
		$("#selectStr").val("ddsdsds");
		alert($("#selectStr").val());
		return true;
	}
	function process(responseJson) {
		if (responseJson.code == 0) {
			$.ligerDialog.error(responseJson.message);
			return;
		} else {
			
		}
	}

	function insert(){
        $.ligerDialog.open({ url: 'role/insert.do', height: 300, width: 400, buttons: [
            { text: '确定', onclick: function (item, dialog) {
            	dialog.frame.$("form:first").submit();
            },cls:'l-dialog-btn-highlight' },
            { text: '取消', onclick: function (item, dialog) { dialog.close(); } }
         ], isResize: true,title:'新增'
        });
    }
	
	function configRight(id){
        $.ligerDialog.open({ url: 'roleright/update.do?id='+id, height: 600, width: 400,isResize: true,title:'权限配置'
        });
    }
	
	function configUser(id){
        $.ligerDialog.open({ url: 'roleuser/list.do?id='+id, height: 600, width: 800,isResize: true,title:'用户配置'
        });
    }
	
	function updateItem(id){
        $.ligerDialog.open({ url: 'role/update.do?id='+id, height: 300, width: 400, buttons: [
            { text: '确定', onclick: function (item, dialog) {
            	dialog.frame.$("form:first").submit();
            },cls:'l-dialog-btn-highlight' },
            { text: '取消', onclick: function (item, dialog) { dialog.close(); } }
         ], isResize: true,title:'修改'
        });
    }
	
	function deleteItem(id){
		var url = "<%=basePath%>role/delete.do";
		$.post(url,{id:id},function(data){
			var responseJson = eval('(' + data + ')');
			   if(responseJson.code==0)
			   {
				   $.ligerDialog.error("删除出错");
	         		return;
			   }else{
		    		window.pagerForm.submit();
			   }
		});
    	
	}
	
  </script>
 </head>
<body>
	<div style="width: 100%;">
		<div style="margin: auto;margin-top: 10px;">
			<form id="roleForm" method="post" action="role/list.do">
				<table>
					<tr>
						<td><label for="name">角色名称:</label></td>
						<td><input type="text" name="rolename" id="rolename"
							value="${roleName }" class="ldText" /></td>
						<td><input type="submit" id="btn_search" name="btn_search" value="查询" class="ldBtnBlue" /></td>
					</tr>
				</table>
			</form>
		</div>
		<hr />
		<div>
			<table border="0" cellspacing="0" cellpadding="0" width="100%" class="ld-datagrid">
				<tr>
					<th >序号</th>
					<th >名称</th>
					<th >操作</th>
				</tr>
				<c:forEach items="${list}" var="role" varStatus="status">
					<tr>	
						<td>${status.count}</td>
						<td>${role.roleName }</td>
						<td >
							<c:if test="${role.sysDefault == 0 }">
								<input type="button" value="修改" onclick="updateItem('${role.id }')" class="ldBtnLink" />
								<input type="button" value="删除" onclick="deleteItem('${role.id }')" class="ldBtnLink" />
							</c:if>
							<input type="button" value="用户配置" onclick="configUser('${role.id }')" class="ldBtnLink" />
							<input type="button" value="权限配置" onclick="configRight('${role.id }')" class="ldBtnLink" />
					</tr>
				</c:forEach>
			</table>
		</div>
		<hr />
		<div>
			<div style="float: left;">
				<input type="button" id="btn_insert" onclick="insert()" value="新增" class="ldBtnGray" />
			</div>
			<div style="float: right;">
				<form action="role/list.do" name="pagerForm" id="pagerForm" method="post">
					<jt:pager action="pagerForm" />
				</form>
			</div>
		</div>
	</div>
</body>
</html>

